<?php
$section = 'service';

$titre = _LB_SERVICE_MANAGEMENT;
$smarty->assign("titre", $titre);

Session::setBackLink($section);

$service = new Service_Booking();
$query = "SELECT SB.*, SG.TITLE TITLE_GROUP, SG.POS GPOS FROM SERVICE_GROUP SG "
        . "LEFT JOIN SERVICE_BOOKING SB ON SB.ID_SERVICE_GROUP = SG.ID "
        . "ORDER BY SG.POS, SG.TITLE, SB.POS,SB.TITLE DESC";

$args = array();
$pager = new  DBPager($service,$args, false ,PAGING_DEFAULT_ITEM_PER_PAGE,$query);
$service->query($query);
$oldName = "";
$arrData = array();
while($service->fetch()){
	if(!isset($arrData[$service->ID_SERVICE_GROUP])){
		$arrData[$service->ID_SERVICE_GROUP] = array("TITLE"=>$service->TITLE_GROUP . " ({$service->GPOS})","DATA"=>array());
	}
	$arrData[$service->ID_SERVICE_GROUP]["DATA"][] = array(
		"ID"=>$service->ID,
		"TITLE"=>$service->TITLE . " ($service->POS)",
		"TIME"=>$service->TIME,
		"PRICE"=>$service->PRICE,
	);
}
$cfer = new Cfer(array(
	_LB_ACCUEIL => Utils::getHomeLink(),
	_LB_SERVICE_MANAGEMENT => Utils::getCurrentLink()));

$smarty->assign('cfer', $cfer);
$smarty->assign('service', $arrData);
$smarty->assign('service_booking', new Service_Booking());
$smarty->assign('service_group', new Service_Group());
$smarty->assign('pager', $pager);
$smarty->display('service_booking_list.html');